//
//  CustomNewsAmountTableViewCell.m
//  AmountBody
//
//  Created by smm on 2018/1/11.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "CustomNewsAmountTableViewCell.h"
static const CGFloat TetiButton_Tag = 410000;
static const CGFloat TetiView_Tag = 420000;
static const CGFloat StyleButton_Tag = 430000;
static const CGFloat StyleView_Tag = 440000;
static const CGFloat JianGeW = 0;
@implementation CustomNewsAmountTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle =UITableViewCellSelectionStyleNone;
        [self loadUI];
    }
    return self;
}
-(void)loadUI
{
    
    if (!self.tetiImage) {
        self.tetiImage = [[UIImageView alloc]init];
        [self addSubview:self.tetiImage];

    }
    
    if (!self.tetiView) {
        self.tetiView = [[SpecialView alloc]init];
        [self addSubview:self.tetiView];

    }
    
    if (!self.styleView) {
        self.styleView = [[SpecialView alloc]init];
        [self addSubview:self.styleView];

    }
    
    if (!self.rulerView) {
        self.rulerView = [[CustomRulerNewsView alloc]init];
        [self addSubview:self.rulerView];

    }
    
}
-(void)setUIForNUlL
{
    self.styleView.hidden = YES;
    [self.styleView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
    }];
    self.rulerView.hidden = YES;
    [self.rulerView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
    }];
    self.tetiView.hidden = YES;
    [self.tetiView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
    }];
    self.tetiImage.hidden = YES;
    [self.tetiImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        
    }];
}
-(void)setCellWithModel:(EssentialModel*)model
{
//    for (UIView * view in self.subviews) {
//        [view removeFromSuperview];
//    }
    [self setUIForNUlL];
    switch (_amountType) {
        case AmountCellTypeForSize:
        {
            [self setCellForSize];
            
        }
            break;
        case AmountCellTypeForTeTi:
        {
            [self setCellForTeti];
            [_tetiView mas_updateConstraints:^(MASConstraintMaker *make) {
                
                make.bottom.equalTo(_tetiImage).offset(-20);
                
            }];
        }
            break;
        case AmountCellTypeForTeTiAndStyle:
        {
            [self setCellForTetiAndStyle];
        }
            break;
        case AmountCellTypeForNomal:
        {
            [self setCellForNomal];
        }
            break;
        case AmountCellTypeForHead:
        {
            [self setCellForHead];
        }
            break;
        default:
            break;
    }
    
}

-(void)setCellForSize
{
    _rulerView.hidden = NO;
    [_rulerView mas_remakeConstraints:^(MASConstraintMaker *make){
        make.bottom.right.top.equalTo(self);
        make.left.equalTo(self).offset(JianGeW);
    }];
    [_rulerView loadRulerNewsViewForSize];

}

-(void)setCellForNomal
{
    _rulerView.hidden = NO;
    [_rulerView mas_remakeConstraints:^(MASConstraintMaker *make){
        make.bottom.right.top.equalTo(self);
        make.left.equalTo(self).offset(JianGeW);
    }];
    [_rulerView loadRulerNewsViewForNomal];

}
-(void)setCellForHead
{
     _rulerView.hidden = NO;
    [_rulerView mas_remakeConstraints:^(MASConstraintMaker *make){
        make.bottom.right.top.equalTo(self);
        make.left.equalTo(self).offset(JianGeW);
    }];
    [_rulerView loadRulerNewsViewForHead];

}
-(void)setCellForTeti
{

    _tetiImage.hidden = NO;
    _tetiView.hidden = NO;
    CGFloat top = 100; // 顶端盖高度
    CGFloat bottom = 20 ; // 底端盖高度
    CGFloat left = 80;
    CGFloat right = 20;
    UIImage * image = [UIImage imageNamed:@"c_kuanshi"];
    // 指定为拉伸模式，伸缩后重新赋值
    image = [image stretchImageWithInsetsTop:top left:left bottom:bottom right:right];
    _tetiImage.image = image;
    [_tetiImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.top.equalTo(self);
        make.left.equalTo(self).offset(JianGeW);
    }];
    left = 50;
    _tetiImage.userInteractionEnabled = YES;
    [_tetiView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_tetiImage).offset(left);
        make.right.equalTo(_tetiImage).offset(-right);
        make.top.equalTo(_tetiImage).offset(top+10);
//        make.bottom.equalTo(_tetiImage).offset(bottom);
    }];

    NSArray * nameArray = @[@"人体形态",@"左肩",@"右肩",@"肚型",@"手臂",@"臂型",@"背型"];
    _tetiView.modelArray = [NSMutableArray arrayWithArray:nameArray];
    _tetiView.Button_Tag = TetiButton_Tag;
    _tetiView.View_Tag = TetiView_Tag;
    _tetiView.backColor = ZhuBack_color;
    [_tetiView loadUIForMasonry];
}

-(void)setCellForTetiAndStyle
{
    
    [self setCellForTeti];
    _styleView.hidden = NO;
    CGFloat right = 20;
    CGFloat left = 50;
    if (_style_nameView) {
        [_style_nameView removeFromSuperview];
    }
    _style_nameView = [[UIView alloc]init];
    [_tetiImage addSubview:_style_nameView];
    [_style_nameView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_tetiImage).offset(left);
        make.top.equalTo(_tetiView.mas_bottom).offset(5);
        make.height.equalTo(@(30));
    }];
    CGFloat td_imageW = 3;
    CGFloat td_imageH = 15;
    UIView *s_dianView = [[UIView alloc]init];
     [_style_nameView addSubview:s_dianView];
    [s_dianView setYuanJiaoForRadius:3.0 andMasks:NO];
    [s_dianView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.top.equalTo(@((30-td_imageH)/2.0));
        make.width.equalTo(@(td_imageW));
        make.height.equalTo(@(td_imageH));
    }];
    s_dianView.backgroundColor = RGBColorAlpha(44, 44, 44, 1);
   
    
    UILabel * s_titleLabel = [[UILabel alloc]init];
    [_style_nameView addSubview:s_titleLabel];
    [s_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(s_dianView.mas_right).offset(5);
        make.top.equalTo(@((30-Nomal_Label_H)/2.0));
        make.width.equalTo(@(80));
        make.height.equalTo(@(Nomal_Label_H));
    }];
    s_titleLabel.text = @"着装风格";
    s_titleLabel.textColor = ZhongZi_Color;
    s_titleLabel.font = Cell_Medium_Font;
    
    UIImageView * lineView = [[UIImageView alloc]init];
    [_style_nameView addSubview:lineView];
    lineView.image = [UIImage imageNamed:@"s_line"];
    lineView.contentMode = UIViewContentModeScaleAspectFit;
    [lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_style_nameView).with.offset(30/2.0);
        make.left.equalTo(s_titleLabel.mas_right);
        make.width.equalTo(@(500-150));
        make.height.mas_equalTo(1);
    }];
    [_styleView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_tetiImage).offset(left);
        make.top.equalTo(_style_nameView.mas_bottom).offset(5);
        make.right.equalTo(_tetiImage).offset(-right);
       make.bottom.equalTo(_tetiImage).offset(-20);
    }];
    _styleView.Button_Tag = StyleButton_Tag;
    _styleView.View_Tag = StyleView_Tag;
    _styleView.backColor = ZhuBack_color;
    NSArray * nameArray = @[@"西服",@"西裤"];
    _styleView.modelArray = [NSMutableArray arrayWithArray:nameArray];
    [_styleView loadUIForMasonry];
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
